import { Global } from "./Global";


const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {


    @property({
        type: cc.Node,
        displayName: "草圈"
    })
    CaoQuan: cc.Node = null;

    @property(cc.Node)
    text: cc.Node = null;

    @property(cc.Node)
    title: cc.Node = null;



    @property(cc.Node)
    btnStart: cc.Node = null;

    @property(cc.Node)
    Niu: cc.Node = null;

    @property(cc.Node)
    Feng: cc.Node = null;
    // onLoad () {},

    @property(cc.Node)
    btnMusic: cc.Node = null;
    @property(Global)
    global: Global = null;
    start() {
        cc.director.setDisplayStats(false);
        let action_caoquan = cc.moveTo(1, cc.p(360, -360)).easing(cc.easeIn(0.6));
        let action_caoquan_r = cc.rotateBy(1, 720);
        this.CaoQuan.runAction(cc.spawn(action_caoquan, action_caoquan_r));
        this.btnStart.on("touchstart", this.onStartGame, this);
        this.btnStart.on(cc.Node.EventType.MOUSE_ENTER, this.global.setCursor, this);
        this.btnStart.on(cc.Node.EventType.MOUSE_LEAVE, this.global.clearCursor, this);
        cc.game.addPersistRootNode(this.btnMusic);
    }

    onStartGame() {

        if (this.text.active) {
            cc.director.once(cc.Director.EVENT_BEFORE_SCENE_LOADING, function () {
                var splash = document.getElementById('splash');
                splash.style.display = 'block';
            });
            cc.director.loadScene("Game", function () {
                cc.director.once(cc.Director.EVENT_AFTER_SCENE_LAUNCH, function () {
                    var splash = document.getElementById('splash');
                    splash.style.display = 'none';
                });
            });

        } else {
            this.text.active = true;
            this.title.active = false;
            this.Niu.destroy();
            this.Feng.destroy();
            this.CaoQuan.destroy();
        }
    }
    // update (dt) {},
    onDestroy() {
        this.btnStart.off("touchstart", this.onStartGame, this);
        this.btnStart.off(cc.Node.EventType.MOUSE_ENTER, this.global.setCursor, this);
        this.btnStart.off(cc.Node.EventType.MOUSE_LEAVE, this.global.clearCursor, this);
        this.global.clearCursor();
    }

}
